<?php

namespace Respect\Http\Module;

use Respect\Http\Bootstrappable;
use Respect\Environment\EnvironmentableInterface;

class Cache implements Bootstrappable
{

    public $cacheControl;
    public $ifMatch;
    public $ifModifiedSince;
    public $ifNoneMatch;
    public $ifUnmodifiedSince;
    public $ifRange;
    public $pragma;

    public static function qualify(EnvironmentableInterface $env)
    {
        return $env['HTTP_CACHE_CONTROL']
        || $env['HTTP_IF_MATCH']
        || $env['HTTP_IF_MODIFIED_SINCE']
        || $env['HTTP_IF_NONE_MATCH']
        || $env['HTTP_IF_UNMODIFIED_SINCE']
        || $env['HTTP_IF_RANGE']
        || $env['HTTP_PRAGMA'] ? new static($env) : false;
    }

    public function __construct(EnvironmentableInterface $env)
    {
        $this->cacheControl = $env['HTTP_CACHE_CONTROL'];
        $this->ifMatch = $env['HTTP_IF_MATCH'];
        $this->ifModifiedSince = $env['HTTP_IF_MODIFIED_SINCE'];
        $this->ifNoneMatch = $env['HTTP_IF_NONE_MATCH'];
        $this->ifUnmodifiedSince = $env['HTTP_IF_UNMODIFIED_SINCE'];
        $this->ifRange = $env['HTTP_IF_RANGE'];
        $this->pragma = $env['HTTP_PRAGMA'];
    }

}
